<template>
	<view>
		<view class="topDetail">
			<view class="money">
				{{cardInfo.cost}}
			</view>
			<view class="subtext">
				{{cardInfo.name}}
			</view>
		</view>
		<scroll-view :scroll-top="0" scroll-y="true" class="scroll-Y">
			<view class="title">确认信息</view>
			<view class="confirm">
				<view class="len">
					<image src="../../static/imgs/payment/zfdd_xm@2x.png" mode=""></image>
					<text>姓名</text>
					<input type="text" value="" placeholder="请填写真实姓名"/>
				</view>
				<view class="len">
					<image src="../../static/imgs/payment/zfdd_sj@2x.png" mode=""></image>
					<text>手机</text>
					<input type="number" value="" placeholder="填写手机号码"/>
				</view>
			</view>
			<view class="title">选择支付方式</view>
			<radio-group @change="radioChange">
				<view class="radio">
					<view class="len">
						<image src="../../static/imgs/payment/zfdd_wx@2x.png" mode=""></image>
						<text>微信支付</text>
						<radio value="wx" :checked="payType == 'wx'" color="#FF0000" style="transform:scale(0.8)"/>
					</view>
					<view class="len">
						<image src="../../static/imgs/payment/zfdd_zfb@2x.png" mode=""></image>
						<text>支付宝支付</text>
						<radio value="zfb" :checked="payType == 'zfb'" color="#FF0000" style="transform:scale(0.8)"/>
					</view><view class="len">
						<image src="../../static/imgs/payment/zfdd_xx@2x.png" mode=""></image>
						<text>线下支付</text>
						<radio value="xx" :checked="payType == 'xx'" color="#FF0000" style="transform:scale(0.8)"/>
					</view>
				</view>
			</radio-group>
			<view class="tipinfo">
				<text>继续即同意</text><text class="eps" @click="showXy('hyxy')">《会员协议》</text><text>和</text><text class="eps" @click="showXy('zfxy')">《支付协议》</text>
			</view>
		</scroll-view>
		<view class="bottombtn">
			<button type="default" class="submit-btn" @click="zhifu()">支付</button>
		</view>
		<!-- 会员协议 -->
		<uni-popup ref="xypopup" type="center" @change="handlerPopupStatusChenge($event, 'showXyPopup')">
				<view id="xypopup">
					<view class="title">
						{{xyInfo && xyInfo.title}}
					</view>
					<scroll-view class="c" scroll-y="true">
						<text>
							{{xyInfo && xyInfo.content}}
						</text>
					</scroll-view>
					<view class="bottom">
						<button type="default" @click="$refs['xypopup'].close();">同意</button>
					</view>
			</view>
		</uni-popup>
		<uni-popup ref="qrcodepopup" type="center" @change="handlerPopupStatusChenge($event, 'showQrcodePopup')">
			<view id="qrcodepopup">
				<view class="tip">
					<text>向商家展示此二维码</text>
				</view>
				<view class="qrcode" v-if="qrcodeValue">
					<!-- <canvas id="qrcode"/> -->
					<image :src="qrcodeValue" mode=""></image>
				</view>
				<view class="tip">
					<image src="../../static/imgs/yueke/ykjl_sx@2x.png" mode="" @click="refreshQrcode"></image>
					<text style="color:red;">即将开通会员</text>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import Qr from "@/common/wxqrcode.js";
	var img1 = require('../../static/test/a5.jpg');
	var img2 = require('../../static/test/a4.jpg');
	!img1.startsWith('/') && (img1 = '/' + img1);
	!img2.startsWith('/') && (img2 = '/' + img2);
	const XY_OBJ = {
		hyxy: {title: '会员协议', content: '1.内容1\n2.内容内容内容内容内容内容内容内容内容内容内容\n3.内容内容内容内容内容内容内容内容内容内容内容\n'},
		zfxy: {title: '支付协议', content: '1.内容2\n2.内容内容内容内容内容内容内容内容内容内容内容\n3.内容内容内容内容内容内容内容内容内容内容内容\n'}
	};
	export default {
		data() {
			return {
				cardInfo: {
					name: 'jazz通卡',
					cost: '2988.00'
				},
				payInfo: {
					name: '',
					phone: ''
				},
				payType: 'wx',
        showXyPopup: false,
				showQrcodePopup: false,
				xyInfo: '',
				qrcodeValue: ''
			}
    },
    onBackPress() {
			if (this.showXyPopup) {
				this.$refs['xypopup'].close();
				return true;
			}
			if (this.showQrcodePopup) {
				this.$refs['qrcodepopup'].close();
				return true;
			}
		},
		methods: {
      handlerPopupStatusChenge: function(e, pop) {
				this[pop] = e.show;
      },
			radioChange(evt) {
				this.payType = evt.detail.value;
			},
			showXy: function (name) {
				this.xyInfo = XY_OBJ[name];
				this.$refs['xypopup'].open();
			},
			refreshQrcode: function () {
				this.qrcodeValue = Qr.createQrCodeImg(Math.random().toFixed(2));
			},
			zhifu: function () {
				if (this.payType == 'xx') {
					this.$refs['qrcodepopup'].open();
					this.qrcodeValue = Qr.createQrCodeImg(Math.random().toFixed(2));
				}
				if (this.payType == 'wx') {
					uni.showToast({ title: "微信支付", position:'bottom' });
				}
				if (this.payType == 'zfb') {
					uni.showToast({ title: "支付宝", position:'bottom' });
				}
			}
		},
		onLoad() {
		}
	}
</script>

<style lang="scss" scoped>
.topDetail {
	height: 86px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	border-bottom: 4px solid #eaebea;
	.money {
		color: #cb0e0e;
		font-size: 30px;
		line-height: 30px;
		&::before {
			content: '¥';
			font-size: 16px;
			margin-right: 5px;
		}
	}
	.subtext {
		color: #b0b0b0;
		font-size: 12px;
	}
}

.scroll-Y {
	height: calc(100vh - 90px - 70px);
	// #ifdef H5
	height: calc(100vh - 90px - 70px - 44px);
	// #endif
	.title {
		margin: 10pt;
		font-size: 15px;
		font-weight: bold;
	}
	.confirm {
		margin: 10pt;
		.len {
			display: flex;
			align-items: center;
			margin: 10px 0;
		}
		image {
			width: 24px;
			height: 24px;
		}
		text {
			position: relative;
			font-size: 14px;
			margin: 0 20px 0 5px;
			width: 30px;
			&::after {
				content: '*';
				color: red;
				position: absolute;
				font-size: 12px;
				right: -8px;
				top: 0;
			}
		}
		input {
			flex-grow: 1;
			font-size: 13px;
		}
	}
	.radio {
		margin: 10pt;
		.len {
			position: relative;
			margin: 20px 0;
			display: flex;
			image {
				width: 24px;
				height: 24px;
			}
			text{
				font-size: 15px;
				margin: 0 10px;
			}
			radio {
				position: absolute;
				right: 0;
			}
		}
	}
	.tipinfo {
		position: absolute;
    bottom: 10px;
    width: 100%;
		text-align: center;
		font-size: 12px;
		color: #808080;
		.eps {
			color: #000;
		}
	}
}

.bottombtn {
	position: fixed;
	width: 100%;
	bottom: 0;
	border-top: 2px solid #eaebea;
	height: 68px;
	display: flex;
	align-items: center;
	.submit-btn {
		margin: 0 auto;
	}
}

#xypopup {
	background: #fff;
	width: 300px;
	border-radius: 10px;
	height: 340px;
	position: absolute;
	left: calc(50% - 150px);
	top: calc(50% - 170px);
	.title {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 10px;
		font-size: 15px;
	}
	.bottom {
		height: 46px;
		background: #eaebea;
		display: flex;
		align-items: center;
		border-radius: 0 0 10px 10px;
		button {
			background: #000;
			color: #fff;
			font-size: 13px;
			height: 30px;
			line-height: 30px;
		}
	}
	.c {
		padding: 10pt;
		font-size: 13px;
		box-sizing: border-box;
		height: calc(340px - 46px - 47px);
	}
}
#qrcodepopup {
	background: #fff;
	width: 220px;
	border-radius: 10px;
	height: 280px;
	position: absolute;
	left: calc(50% - 110px);
	top: calc(50% - 140px);
	display: flex;
	flex-direction: column;
	.qrcode {
		width: 150px;
		height: 150px;
		margin: 10px auto 20px;
		image {
			width: 100%;
			height: 100%;
		}
	}
	.tip {
		text-align: center;
		display: flex;
		flex-direction: column;
		align-items: center;
		text {
			padding: 5px 0;
		}
		image {
			width: 16px;
			height: 16px;
		}
	}
}
</style>